home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / shell / cdialog-.9a / cdialog- / cdialog-0.9a / dialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-15  |  8.1 KB  |  279 lines

  1. /*
  2.  *  dialog.h -- common declarations for all dialog modules
  3.  *
  4.  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
  5.  *
  6.  *  This program is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU General Public License
  8.  *  as published by the Free Software Foundation; either version 2
  9.  *  of the License, or (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <sys/types.h>
  22. #include <fcntl.h>
  23. #include <unistd.h>
  24. #include <ctype.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <signal.h>    /* fork() etc. */
  28. #include <math.h>    /* sqrt() */
  29.  
  30. #ifdef ultrix
  31. #include <cursesX.h>
  32. #else
  33. #include <curses.h>
  34. #endif
  35.  
  36. /*
  37.  * Change these if you want
  38.  */
  39. #define USE_SHADOW TRUE
  40. #define USE_COLORS TRUE
  41.  
  42. #define SCOLS    COLS-(use_shadow ? 2 : 0)
  43. #define SLINES    LINES-(use_shadow ? 1 : 0)
  44.  
  45. #define ESC 27
  46. #define TAB 9
  47. #define MAX_LEN 2048
  48. #define BUF_SIZE (10*1024)
  49. #define MIN(x,y) (x < y ? x : y)
  50. #define MAX(x,y) (x > y ? x : y)
  51.  
  52. #define MAX_TAILBG 9
  53. /* default separate_str is a Tab. It's must be a "string" */
  54. #define DEFAULT_SEPARATE_STR "\x9"
  55. #define DEFAULT_ASPECT_RATIO 9
  56. /* how many spaces is a tab long (default)? */
  57. #define TAB_LEN 8
  58. #define WTIMEOUT_VAL        10
  59.  
  60.  
  61. #ifndef HAVE_NCURSES
  62. #ifndef ACS_ULCORNER
  63. #define ACS_ULCORNER '+'
  64. #endif
  65. #ifndef ACS_LLCORNER
  66. #define ACS_LLCORNER '+'
  67. #endif
  68. #ifndef ACS_URCORNER
  69. #define ACS_URCORNER '+'
  70. #endif
  71. #ifndef ACS_LRCORNER
  72. #define ACS_LRCORNER '+'
  73. #endif
  74. #ifndef ACS_HLINE
  75. #define ACS_HLINE '-'
  76. #endif
  77. #ifndef ACS_VLINE
  78. #define ACS_VLINE '|'
  79. #endif
  80. #ifndef ACS_LTEE
  81. #define ACS_LTEE '+'
  82. #endif
  83. #ifndef ACS_RTEE
  84. #define ACS_RTEE '+'
  85. #endif
  86. #ifndef ACS_UARROW
  87. #define ACS_UARROW '^'
  88. #endif
  89. #ifndef ACS_DARROW
  90. #define ACS_DARROW 'v'
  91. #endif
  92. #endif
  93.  
  94. /* 
  95.  * Attribute names
  96.  */
  97. #define screen_attr                   attributes[0]
  98. #define shadow_attr                   attributes[1]
  99. #define dialog_attr                   attributes[2]
  100. #define title_attr                    attributes[3]
  101. #define border_attr                   attributes[4]
  102. #define button_active_attr            attributes[5]
  103. #define button_inactive_attr          attributes[6]
  104. #define button_key_active_attr        attributes[7]
  105. #define button_key_inactive_attr      attributes[8]
  106. #define button_label_active_attr      attributes[9]
  107. #define button_label_inactive_attr    attributes[10]
  108. #define inputbox_attr                 attributes[11]
  109. #define inputbox_border_attr          attributes[12]
  110. #define searchbox_attr                attributes[13]
  111. #define searchbox_title_attr          attributes[14]
  112. #define searchbox_border_attr         attributes[15]
  113. #define position_indicator_attr       attributes[16]
  114. #define menubox_attr                  attributes[17]
  115. #define menubox_border_attr           attributes[18]
  116. #define item_attr                     attributes[19]
  117. #define item_selected_attr            attributes[20]
  118. #define tag_attr                      attributes[21]
  119. #define tag_selected_attr             attributes[22]
  120. #define tag_key_attr                  attributes[23]
  121. #define tag_key_selected_attr         attributes[24]
  122. #define check_attr                    attributes[25]
  123. #define check_selected_attr           attributes[26]
  124. #define uarrow_attr                   attributes[27]
  125. #define darrow_attr                   attributes[28]
  126.  
  127. /* number of attributes */
  128. #define ATTRIBUTE_COUNT               29
  129.  
  130. /*
  131.  * Global variables
  132.  */
  133. #ifdef HAVE_NCURSES
  134. extern bool use_colors;
  135. extern bool use_shadow;
  136. #endif
  137.  
  138. extern chtype attributes[];
  139.  
  140. extern int is_tailbg, print_siz, tab_len, tab_correct;
  141.  
  142. /* Coordinate in begin_y, begin_x  if begin_set == 1 */
  143. extern int begin_y, begin_x, begin_set, aspect_ratio, screen_initialized;
  144.  
  145. extern char *backtitle, *lock_refresh, *lock_tailbg_refreshed,
  146.         *lock_tailbg_exit;
  147. extern int beep_signal, is_tailbg, print_siz, cr_wrap, size_err,
  148.         tab_len, tab_correct;
  149. extern pid_t tailbg_pids[MAX_TAILBG], tailbg_lastpid, tailbg_nokill_pids[MAX_TAILBG], tailbg_nokill_lastpid;
  150.  
  151. /*
  152.  * Function prototypes
  153.  */
  154. #ifdef HAVE_NCURSES
  155. extern void create_rc (const char *filename);
  156. extern int parse_rc (void);
  157. #endif
  158.  
  159.  
  160. void init_dialog (void);
  161. void end_dialog (void);
  162. void attr_clear (WINDOW * win, int height, int width, chtype attr);
  163. void put_backtitle(void);
  164.  
  165. char *auto_size(char *prompt, int *height, int *width, int boxlines, int mincols);
  166. void auto_sizefile(const char *file, int *height, int *width, int boxlines, int mincols);
  167.  
  168. char *make_lock_filename(char *filename);
  169. void wrefresh_lock(WINDOW *win);
  170. void ctl_idlemsg(WINDOW *win);
  171. void wrefresh_lock_tailbg(WINDOW *win);
  172. void wrefresh_lock_sub(WINDOW *win);
  173.  
  174. int exist_lock(char *filename);
  175. void while_exist_lock(char *filename);
  176. void create_lock(char *filename);
  177. void remove_lock(char *filename);
  178.  
  179. void killall_bg(void);
  180. void quitall_bg(void);
  181. void exiterr(char *);
  182. void beeping(void);
  183. void print_size(int height, int width);
  184. void ctl_size(int height, int width);
  185. void tab_correct_str(char *prompt);
  186. void calc_listh(int *height, int *list_height, int item_no);
  187. int calc_listw(int item_no, const char * const * items, int group);
  188. char *strclone(const char *cprompt);
  189.  
  190. #ifdef HAVE_NCURSES
  191. void color_setup (void);
  192. #endif
  193. void print_autowrap(WINDOW *win, const char *prompt, int width, int y, int x);
  194. void print_button (WINDOW * win, const char *label, int y, int x, int selected);
  195. void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
  196.         chtype border);
  197. #ifdef HAVE_NCURSES
  198. void draw_shadow (WINDOW * win, int y, int x, int height, int width);
  199. #endif
  200.  
  201. int dialog_yesno (const char *title, const char *cprompt, int height, int width);
  202. int dialog_msgbox (const char *title, const char *cprompt, int height,
  203.         int width, int pause);
  204. int dialog_textbox (const char *title, const char *file, int height, int width);
  205. int dialog_menu (const char *title, const char *cprompt, int height, int width,
  206.         int menu_height, int item_no, const char * const * items);
  207. int dialog_checklist (const char *title, const char *cprompt, int height,
  208.         int width, int list_height, int item_no,
  209.         const char * const * items, int flag, int separate_output);
  210. extern unsigned char dialog_input_result[];
  211. int dialog_inputbox (const char *title, const char *cprompt, int height,
  212.         int width, const char *init);
  213. int dialog_guage (const char *title, const char *cprompt, int height, int width,
  214.         int percent);
  215. int dialog_tailbox (const char *title, const char *file, int height, int width);
  216. void dialog_tailboxbg (const char *title, const char *file, int height, int width, int cant_kill);
  217.  
  218. /*
  219.  * The following stuff is needed for mouse support
  220.  */
  221. #ifndef HAVE_LIBGPM
  222.  
  223. extern __inline__ void
  224. mouse_open (void)
  225. {
  226. };
  227. extern __inline__ void
  228. mouse_close (void)
  229. {
  230. };
  231. extern __inline__ void
  232. mouse_mkregion (int y, int x, int height, int width,
  233.         int code)
  234. {
  235. };
  236. extern __inline__ void
  237. mouse_mkbigregion (int y, int x, int height, int width,
  238.            int nitems, int th, int mode)
  239. {
  240. };
  241. extern __inline__ void
  242. mouse_setbase (int x, int y)
  243. {
  244. };
  245.  
  246. #else
  247.  
  248. void mouse_open (void);
  249. void mouse_close (void);
  250. void mouse_mkregion (int y, int x, int height, int width, int code);
  251. void mouse_mkbigregion (int y, int x, int height, int width, int nitems,
  252.             int th, int mode);
  253. void mouse_setbase (int x, int y);
  254.  
  255. #endif
  256.  
  257. int mouse_wgetch (WINDOW *);
  258.  
  259. #define mouse_mkbutton(y,x,len,code) mouse_mkregion(y,x,1,len,code);
  260.  
  261. /*
  262.  * This is the base for fictious keys, which activate
  263.  * the buttons.
  264.  *
  265.  * Mouse-generated keys are the following:
  266.  *   -- the first 32 are used as numbers, in addition to '0'-'9'
  267.  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  268.  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  269.  */
  270. #define M_EVENT (KEY_MAX+1)
  271.  
  272.  
  273. /*
  274.  * The `flag' parameter in checklist is used to select between
  275.  * radiolist and checklist
  276.  */
  277. #define FLAG_CHECK 1
  278. #define FLAG_RADIO 0
  279.